#!/bin/bash

# Set to 1 for debug builds, 0 for release
DEBUG=1
OS=`uname`

# Guess where are we and go to that dir
CURDIR=$(dirname $0)
cd $CURDIR

# Create the paths to the BennuGD binaries and to
# the needed libraries 
if [[ $OS = "Darwin" ]]; then
        BINDIR=$CURDIR/bin_osx
else
        BINDIR=$CURDIR/bin
fi
LIBDIR=$BINDIR/lib

# Set the required env vars, giving our bundled version
# of BennuGD priority over a (possibly) installed version.
export PATH=$BINDIR:$PATH
if [[ $OS = "Darwin" ]]; then
	export DYLD_LIBRARY_PATH=$LIBDIR::$DYLD_LIBRARY_PATH:$BINDIR/modules
	export PANGO_RC_FILE=$BINDIR/etc/pangorc
	export FONTCONFIG_PATH=$BINDIR/etc/fonts
else
	export LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH
fi

# Delete the old DCB and compile (if needed)
if [ $DEBUG = 1 ]; then
	if [ -f main.dcb ]; then
		rm main.dcb
	fi

	if [ $OS = "Darwin" ]; then
		bgdc -DOSX main.prg
	else
		bgdc -DDEBUG main.prg
	fi
fi

# And run
if [ -f main.dcb ]; then
	bgdi main
fi
